﻿//==============================================================
//  Copyright (C) 2017 JonneyDong Inc. All rights reserved.
//
//==============================================================
//  Create by JonneyDong at 2017/3/2 18:23:47.
//  Version 1.0
//  JonneyDong [mailto:jonneydong@gmail.com]
//==============================================================
using ServiceStack.Redis;
using ServiceStack.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yoze.Redis.Common
{
    /// <summary>
    /// 缓存客户端管理器工厂
    /// </summary>
    public class PoolManagerFactory
    {
        private static PooledRedisClientManager Manager = null;
        public static PooledRedisClientManager CreateManager(string[] readWriteHosts, string[] readOnlyHosts, int initialDB = 0)
        {
            if (Manager == null)
            {
                Manager = new PooledRedisClientManager(readWriteHosts, readOnlyHosts, new RedisClientManagerConfig()
                {
                    MaxWritePoolSize = 50,
                    MaxReadPoolSize = 50,
                    AutoStart = true
                }, initialDB, 100, 0);
            }

            JsConfig<DateTime>.SerializeFn = time => new DateTime(time.Ticks, DateTimeKind.Local).ToString();
            JsConfig<DateTime?>.SerializeFn = time => time != null ? new DateTime(time.Value.Ticks, DateTimeKind.Local).ToString() : null;
            
            //JsConfig<PermissionActions>.DeSerializeFn = e => (PermissionActions)int.Parse(e);
            return Manager;
        }

    }
}
